package com.cwrl.spider.server.test.flow.price.node;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.NumberUtil;
import com.cwrl.spider.server.test.flow.price.PriceContext;
import com.yomahub.liteflow.annotation.LiteflowComponent;
import com.yomahub.liteflow.core.NodeComponent;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.Objects;

/**
 * @author cw
 */
@LiteflowComponent(value = "discountNode", name = "满减节点")
public class DiscountNodeComponent extends NodeComponent {
    @Override
    public void process() throws Exception {
        System.out.println("满减节点");
        PriceContext contextBean = this.getContextBean(PriceContext.class);
        if (Objects.isNull(contextBean.getTotalPrice())) {
            return;
        }

        // 满200 减 30
        contextBean.setTotalPrice(NumberUtil.sub(contextBean.getTotalPrice(),
                contextBean.getTotalPrice().divide(BigDecimal.valueOf(200), 0, RoundingMode.DOWN).multiply(BigDecimal.valueOf(30))));
    }

    @Override
    public boolean isAccess() {
        return super.isAccess();
    }
}
